package m_simple;

import com.rabbitmq.client.*;


import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Consumer {

    public static void main(String[] args) throws IOException, TimeoutException {
        //连接
        ConnectionFactory f=new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setPort(5672);
        f.setUsername("admin");
        f.setPassword("admin");
            //队列 消费者 和提供者谁先启动谁创建队列
            Connection con = f.newConnection();
        //通道
        Channel c = con.createChannel();

        c.queueDeclare("hell", false, false, false, null);
        System.out.println("等待;连接");
    //接受的回调对象
        DeliverCallback callback = new DeliverCallback() {

            @Override
            public void handle(String s, Delivery delivery) throws IOException {
                String mag=new String(delivery.getBody());
                System.out.println("收到消息"+mag);
            }
        };
        CancelCallback cancel = new CancelCallback(){

            @Override
            public void handle(String s) throws IOException {

            }
        };
        //接收

        c.basicConsume("hell", true, callback, cancel);

    }

}
